import axios from 'axios';
import { Card } from '../../types';

const API_BASE = '/api/cards';

// 获取今日需要复习的卡片
export async function fetchReviewCards(notebookId?: string): Promise<Card[]> {
  const params = notebookId ? { notebook_id: notebookId, review: 'true' } : { review: 'true' };
  const res = await axios.get(API_BASE, { params });
  return res.data.map((card: any) => ({
    ...card,
    createdAt: new Date(card.created_at),
    nextReview: new Date(card.next_review),
    easeFactor: card.ease_factor,
    notebookId: card.notebook_id,
    repetition: card.repetition,
    interval: card.interval
  }));
}

// 提交卡片复习结果
export async function submitCardReview(cardId: string, quality: number): Promise<Card> {
  const res = await axios.post(`${API_BASE}/${cardId}/review`, { quality });
  return {
    ...res.data,
    createdAt: new Date(res.data.created_at),
    nextReview: new Date(res.data.next_review),
    easeFactor: res.data.ease_factor,
    notebookId: res.data.notebook_id,
    repetition: res.data.repetition,
    interval: res.data.interval
  };
} 